package _15_generics._15_8;

import java.lang.reflect.Array;

/**
 * 使用类型标记创建实际类型的数组
 */
public class _08_GenericArrayWithTypeToken<T> {

    private T[] array;

    public _08_GenericArrayWithTypeToken(Class<T> kind,int size){
        array = (T[]) Array.newInstance(kind,size);
    }

    public T get(int index){
        return array[index];
    }

    public T[] rep(){
        return array;
    }

    public static void main(String[] args) {
        _08_GenericArrayWithTypeToken<Integer> gai =
                new _08_GenericArrayWithTypeToken(Integer.class,5);
        Integer[] rep = gai.rep();
        System.out.println(rep);
    }
}
